@{
    ViewBag.Title = "高强度密码生成器,密码生成器GetPassword";
    ViewBag.keywords = "高强度密码,密码在线生成,密码生成器GetPassword,高强度密码在线生成";
    ViewBag.description = "是一个帮助你生成高强度密码的工具，你可以选择密码长度，是否包含标点符号，系统会自动为你生成一个难以破解的密码";
}
@section Styles{
<style>.layui-form-checkbox i {border-left: 1px solid #d2d2d2;}</style>
}
<div class="layui-row layui-form layui-form-pane">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">密码长度：</label>
        <div class="layui-input-block">
            <select id="ddlLength">
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15" selected="selected">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option>
                <option value="32">32</option>
                <option value="33">33</option>
                <option value="34">34</option>
                <option value="35">35</option>
                <option value="36">36</option>
                <option value="37">37</option>
                <option value="38">38</option>
                <option value="39">39</option>
                <option value="40">40</option>
                <option value="41">41</option>
                <option value="42">42</option>
                <option value="43">43</option>
                <option value="44">44</option>
                <option value="45">45</option>
                <option value="46">46</option>
                <option value="47">47</option>
                <option value="48">48</option>
                <option value="49">49</option>
                <option value="50">50</option>
                <option value="51">51</option>
                <option value="52">52</option>
                <option value="53">53</option>
                <option value="54">54</option>
                <option value="55">55</option>
                <option value="56">56</option>
                <option value="57">57</option>
                <option value="58">58</option>
                <option value="59">59</option>
                <option value="60">60</option>
                <option value="61">61</option>
                <option value="62">62</option>
                <option value="63">63</option>
                <option value="64">64</option>
                <option value="65">65</option>
                <option value="66">66</option>
                <option value="67">67</option>
                <option value="68">68</option>
                <option value="69">69</option>
                <option value="70">70</option>
                <option value="71">71</option>
                <option value="72">72</option>
                <option value="73">73</option>
                <option value="74">74</option>
                <option value="75">75</option>
                <option value="76">76</option>
                <option value="77">77</option>
                <option value="78">78</option>
                <option value="79">79</option>
                <option value="80">80</option>
                <option value="81">81</option>
                <option value="82">82</option>
                <option value="83">83</option>
                <option value="84">84</option>
                <option value="85">85</option>
                <option value="86">86</option>
                <option value="87">87</option>
                <option value="88">88</option>
                <option value="89">89</option>
                <option value="90">90</option>
                <option value="91">91</option>
                <option value="92">92</option>
                <option value="93">93</option>
                <option value="94">94</option>
                <option value="95">95</option>
                <option value="96">96</option>
                <option value="97">97</option>
                <option value="98">98</option>
                <option value="99">99</option>
                <option value="100">100</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <div class="layui-input-block">
            <input id="chkSymbols" checked="checked" type="checkbox" class="layui-input" />
            <label for="chkSymbols">包含标点符号 (<kbd>!</kbd>, <kbd>"</kbd>, <kbd>£</kbd>, <kbd>$</kbd>, <kbd>%</kbd>等等)</label>
        </div>
    </div>
    <div class="layui-form-item">
            <a class="layui-btn" id="btnGenerate" onclick="displayPassword();">生成高强度密码</a>
            <a class="layui-btn layui-btn-primary copy" onclick="copytxt();">复制结果</a>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">新密码是：</label>
        <div class="layui-input-block" style="margin:10px 0px;">
            <span id="outputPassword" tabindex="-1" aria-live="assertive" spellcheck="false" style="border:1px double;padding:4px;color:red;width:100%;">你的新密码将显示在这里</span>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">方式记密码:</label>
        <div class="layui-input-block">
            <span id="outputMnemonic" spellcheck="false" style="border:1px double;color:brown;padding:4px;line-height: 40px;">可按照这种方式记住密码</span>
        </div>
    </div>
</div>
<div class="layui-form-item layui-form-text">
    <div class="layui-elem-quote">
        <article role="article" aria-labelledby="IsThisSecure" class="alert alert-warning">
            <h3 id="IsThisSecure">生成的密码保密吗?</h3>
            <p>是的. 本站生成的密码是通过JS脚本在浏览器内生成，不通过Internet传输</p>
        </article>
    </div>
</div>
<div class="layui-elem-quote">
    <article role="article" aria-labelledby="StrongPasswordGuidelines" class="alert alert-info">
        <h3 id="StrongPasswordGuidelines">什么样的密码算是高强度密码</h3>
        <dl>
            <dt>一个强壮的密码包含:</dt>
            <dd>至少包含 <strong>15 个字符</strong>;</dd>
            <dd>包含 <strong>大写字母</strong>;</dd>
            <dd>包含 <strong>小写字母</strong>;</dd>
            <dd>包含 <strong>数字</strong>;</dd>
            <dd>包含 <strong>符号</strong>, 如 <kbd>` ! " ? $ ? % ^ &amp; * ( ) _ - + = { [ } ] : ; @@ ' ~ # | \ &lt; , &gt; . ? /</kbd></dd>
        </dl>
    </article>
</div>
<div class="layui-elem-quote">
    <dl>
        <dd>不能类似以前使用过的密码</dd>
        <dd>不能包含你的名字</dd>
        <dd>不能是你的登录名</dd>
        <dd>不能是你朋友的名字，尤其是女朋友</dd>
        <dd>不能是你家庭成员的名字，包括狗狗</dd>
        <dd>不能是字典中的某个单词</dd>
        <dd>不能是常用的人名</dd>
        <dd>不能是在键盘上经常连续敲击的字符串比如： <kbd>asdfghjkl</kbd>, or <kbd>12345678</kbd>.</dd>
    </dl>
</div>
@section Scripts{
<script>
    var theSymbols = [" ", "!", "\"", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", ";", ":", "'", "@@", "#", "~", "|", ",", "<", ".", ">", "/", "?"]; //Removed "\\", because backslash character can cause problems when passwords are stored.
    function GeneratePassword(lengthOfPassword, wantSymbols) {
        var theLetters = "abcdefghijklmnopqrstuvwxyz";
        var StrongPasswordArray = [];
        var capitalise;
        for (var i = 0; i < lengthOfPassword; i++) {
            capitalise = Math.round(Math.random() * 1);
            if (capitalise === 0) {
                StrongPasswordArray[i] = theLetters.charAt(Math.floor(Math.random() * 26)).toUpperCase();
            }
            else {
                StrongPasswordArray[i] = theLetters.charAt(Math.floor(Math.random() * 26));
            }
        }
        var numberOfDigits;
        numberOfDigits = Math.round(Math.random() * (lengthOfPassword - 1)) + 1;
        var positionForNumeric, theNumber;
        for (i = 0; i < numberOfDigits; i++) {
            positionForNumeric = Math.round(Math.random() * (lengthOfPassword - 1));
            theNumber = Math.round(Math.random() * 9);
            StrongPasswordArray[positionForNumeric] = theNumber;
        }
        if (wantSymbols) {
            var numberOfSymbols;
            numberOfSymbols = Math.round(Math.random() * (lengthOfPassword - 1)) + 1;
            var positionForSymbol;
            var locationOfSymbolInArray;
            var theSymbol;
            for (i = 0; i < numberOfSymbols; i++) {
                positionForSymbol = Math.round(Math.random() * (lengthOfPassword - 1));
                locationOfSymbolInArray = Math.round(Math.random() * (theSymbols.length - 1));
                theSymbol = theSymbols[locationOfSymbolInArray];
                StrongPasswordArray[positionForSymbol] = theSymbol;
            }
        }
        return StrongPasswordArray;
    }
    function copytxt(){ 
    var txt = document.getElementById("outputPassword").firstChild.textContent; if (txt === undefined || txt === '' || txt === null) {  layer.msg("没有输出内容.", { icon: 2 }); return; } if (XEClipboard.copy(txt)) { layer.msg("复制成功.", { icon: 1 }); } else { layer.msg("复制失败.", { icon: 2 }); } }
    function Validate(StrongPasswordArray, lengthOfPassword, wantSymbols) {
        var hasAnUpperCaseLetter = false;
        var hasALowerCaseLetter = false;
        var hasANumber = false;
        var hasASymbol = false;
        var correctLength = false;
        for (var i = 0; i < StrongPasswordArray.length; i++) {
            if ("A" <= StrongPasswordArray[i] && StrongPasswordArray[i] <= "Z") {
                hasAnUpperCaseLetter = true;
                break;
            }
        }
        for (i = 0; i < StrongPasswordArray.length; i++) {
            if ("a" <= StrongPasswordArray[i] && StrongPasswordArray[i] <= "z") {
                hasALowerCaseLetter = true;
                break;
            }
        }
        for (i = 0; i < StrongPasswordArray.length; i++) {
            if ("0" <= StrongPasswordArray[i] && StrongPasswordArray[i] <= "9") {
                hasANumber = true;
                break;
            }
        }
        if (wantSymbols) {
            for (i = 0; i < StrongPasswordArray.length; i++) {
                for (var iSymbols = 0; iSymbols < theSymbols.length; iSymbols++) {
                    if (StrongPasswordArray[i] == theSymbols[iSymbols]) {
                        hasASymbol = true;
                        break;
                    }
                }
            }
        }
        if (StrongPasswordArray.length == lengthOfPassword) {
            correctLength = true;
        }
        if (!wantSymbols) {
            hasASymbol = true;
        }
        if (!hasAnUpperCaseLetter || !hasALowerCaseLetter || !hasANumber || !hasASymbol || !correctLength) {
            lengthOfPassword = "";
            loop = "";
            hasAnUpperCaseLetter = "";
            hasALowerCaseLetter = "";
            hasANumber = "";
            hasASymbol = "";
            correctLength = "";
            return false;
        }
        else {
            return true;
        }
    }
    function MakeMnemonic(StrongPasswordArray) {
        var theWords = [];
        theWords = ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "x-ray", "yankee", "zulu"];
        var lettersArray = [];
        lettersArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
        var easyToRememberArray = [];
        for (var i = 0; i < StrongPasswordArray.length; i++) {
            for (var iLetters = 0; iLetters < lettersArray.length; iLetters++) {
                if (StrongPasswordArray[i] == lettersArray[iLetters].toUpperCase()) {
                    easyToRememberArray[i] = theWords[iLetters].toUpperCase() + "\n";
                }
                if (StrongPasswordArray[i] == lettersArray[iLetters]) {
                    easyToRememberArray[i] = theWords[iLetters] + "\n";
                }
            }
            if ("0" <= StrongPasswordArray[i] && StrongPasswordArray[i] <= "9") {
                easyToRememberArray[i] = StrongPasswordArray[i];
            }
            for (var iSymbols = 0; iSymbols < theSymbols.length; iSymbols++) {
                if (StrongPasswordArray[i] == theSymbols[iSymbols]) {
                    easyToRememberArray[i] = StrongPasswordArray[i];
                    /* use "[space]" to represent a space character */
                    if (StrongPasswordArray[i] === " ") {
                        easyToRememberArray[i] = "[space]";
                    }
                }
            }
        }
        var easyToRemember = "";
        for (i = 0; i < easyToRememberArray.length; i++) {
            easyToRemember += easyToRememberArray[i] + " ";
        }
        return easyToRemember;
    }
    function displayPassword() {
        var newStrongPasswordArray;
        var passwordIsOK = false;
        while (!passwordIsOK) {
            newStrongPasswordArray = GeneratePassword(document.getElementById("ddlLength").options[document.getElementById("ddlLength").selectedIndex].value, document.getElementById("chkSymbols").checked);
            passwordIsOK = Validate(newStrongPasswordArray, document.getElementById("ddlLength").options[document.getElementById("ddlLength").selectedIndex].value, document.getElementById("chkSymbols").checked);
        }
        var StrongPassword = "";
        for (var i = 0; i < newStrongPasswordArray.length; i++) {
            StrongPassword += newStrongPasswordArray[i];
        }
      
        document.getElementById("outputPassword").replaceChild(document.createTextNode(StrongPassword), document.getElementById("outputPassword").firstChild);
        document.getElementById("outputPassword").focus();
        var c=MakeMnemonic(newStrongPasswordArray);
        document.getElementById("outputMnemonic").replaceChild(document.createTextNode(c), document.getElementById("outputMnemonic").firstChild);
    }
</script>
    }